package gxb.test13;

import java.util.Scanner;
//todo 还未完成的项目
public class StudentScore {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s=scanner.nextLine();
        //判断是否
        while(s.equals("new")){
            System.out.print("请输入姓名：");
            String name = scanner.nextLine();
            System.out.print("请输入成绩：");
            int score = scanner.nextInt();
            Student student = new Student(name,score);
            try {
                student.addScore(score);
                System.out.println(student.toString());
            }catch (IllegalScoreException e){
                System.out.println("IllegalScoreException："+e.getMessage());
            }
            scanner.nextLine();
            s=scanner.nextLine();
        }

    }
}
class Student{
    private String name;
    private int score;

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    public void addScore(int scoreToAdd) throws IllegalScoreException{
        if(scoreToAdd+score > 200) {
            throw new IllegalScoreException(score);
        }
        score=scoreToAdd;
    }

    @Override
    public String toString() {
        return "Student[" +
                "name='" + name + '\'' +
                ", score=" + score +
                ']';
    }
}
class IllegalScoreException extends RuntimeException{
    public IllegalScoreException(int score){
        super("成绩超过有效范围,成绩为=" + score);
    }
}

